import Vue from 'vue'
import Vuex from 'vuex'
import VuexPersistence from 'vuex-persist'
import {getPowers} from '@/axios/power'
Vue.use(Vuex)

const vuexLocal = new VuexPersistence({
  storage: window.sessionStorage
})

var state = {
  user:{},
  powers:[],
};
var getters = {};
var mutations = {
  getuser(state,user){
    state.user = user
  },
  powersList(state,data){ 
    state.powers = data
  },
};
var actions = {
  async getPowerList(context){
    let {data} = await getPowers()
    if(data.code != 200 ){
      context.commit('powersList','获取失败！')  
    }
    context.commit('powersList',data.data)
  },
};
export default new Vuex.Store({
 state,
 getters,
 mutations,
 actions,
 plugins: [vuexLocal.plugin]
})
